package com.yc.c118s3plyspringboot;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@RestController
public class MailAction {

//    @Resource
//    private JavaMailSender mailSender;
//    @Value("${mail.fromMail.addr}")
//    private String from;
//
//    @GetMapping("send")
//    public String send() {
//        SimpleMailMessage smm = new SimpleMailMessage();
//        smm.setFrom(from);
//        smm.setTo("1120671810@qq.com");
//        smm.setSubject("测试邮件");
//        smm.setText("这是一封测试邮件!");
//        mailSender.send(smm);
//        return "邮件发送成功";
//    }
//
//    // 忘记密码
//    @GetMapping("forget")
//    public String forget() throws MessagingException {
//        MimeMessage message = mailSender.createMimeMessage();
//        MimeMessageHelper helper = new MimeMessageHelper(message, true);
//        helper.setFrom(from);
//        helper.setTo(from);
//        helper.setSubject("忘记密码");
//        helper.setText("<h3></h3>点击链接<a href='#'>重置密码</a>", true);
//        mailSender.send(message);
//        return "重置密码邮件已发送";
//    }
}
